﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Logging;

using ZFB.Common;
using ZFB.IServices;
using ZFB.Models;
using ZFB.Repository.City;

namespace ZFB.WebAPI.Controllers
{
    /// <summary>
    /// 城市
    /// </summary>

    [Route("api/[controller]/[action]")]
    [ApiController]
    public class CityController : ControllerBase
    {
        private readonly ICityServices _services;

        public CityController(ICityServices services)
        {
            _services = services;
        }
        /// <summary>
        /// 添加城市
        /// </summary>
        /// <param name="CityName"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> AddCity(string CityName) 
        {         
            return  await _services.AddCityAsync(CityName);
        }
        /// <summary>
        /// 获取所有城市
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult> Getcity()
        {
            return await _services.GetCityAsync();
        }
        /// <summary>
        /// 根据id获取城市
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> GetById(long id)
        {
            return await _services.GetCityByIdAsync(id);
        }

    }
}
